package com.cobo.fitness.web.fitness.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cobo.fitness.web.fitness.entity.Exercise;
import com.cobo.fitness.web.fitness.entity.Instruction;
import com.cobo.fitness.web.fitness.entity.SecondaryMuscle;
import com.cobo.fitness.web.fitness.mapper.ExerciseMapper;
import com.cobo.fitness.web.fitness.services.ExerciseService;
import com.cobo.fitness.web.fitness.services.InstructionService;
import com.cobo.fitness.web.fitness.services.SecondaryMucleService;
import com.cobo.fitness.web.fitness.vo.ExerciseResVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExerciseServiceImpl  extends ServiceImpl<ExerciseMapper, Exercise> implements ExerciseService {

    @Autowired
    private InstructionService instructionService;

    @Autowired
    private SecondaryMucleService secondaryMucleService;

    @Override
    public ExerciseResVo transformToRes(Exercise it) {
        List<Instruction> instructions = instructionService.lambdaQuery()
                .eq(Instruction::getExerciseId, it.getId())
                .list();
        List<SecondaryMuscle> secondaryMuscles = secondaryMucleService.lambdaQuery()
                .eq(SecondaryMuscle::getExerciseId, it.getId())
                .list();
       return com.cobo.fitness.web.fitness.trans.ExerciseMapper.INSTANCE
                .exerciseAndInstructionAndSecondaryMuscleToExerciseResVo(
                        it, instructions, secondaryMuscles
                );
    }
}
